import javax.swing.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;


public class ClientRecv implements Runnable {
    private ObjectInputStream ois;
    private ObjectOutputStream oos;
    private Socket socket;
    private ChatClient client;
    private JTextField textField;

    public ClientRecv(ChatClient client) {
        this.client = client;
        ois = client.getOis();
        //textField = client.getInputField();
    }

    @Override
    public void run() {
        while (true){
            try {
                System.out.println("ClientRecv");
                String msg = (String) ois.readObject();
                System.out.println(msg);
                client.getShowArea().append(msg+"\n");
                /*int startIndex = msg.indexOf(":");
                String info = msg.substring(startIndex+1);
                if (info.equals("bye")||info.equals("再见")) {
                    this.close();
                    System.exit(0);
                }*/
            } catch (IOException e1) {
                client.close();
                e1.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
        }
    }
}
